package com.zxj.friend.controller.user;

import com.zxj.api.domain.vo.UserQuestionResultVO;
import com.zxj.common.core.contains.HttpConstants;
import com.zxj.common.core.controller.BaseController;
import com.zxj.common.core.domain.R;
import com.zxj.friend.aspect.CheckUserStatus;
import com.zxj.friend.domain.user.dto.UserSubmitDTO;
import com.zxj.friend.service.user.IUserQuestionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/user/question")
@Tag(name = "用户提交题目", description = "用户提交题目相关接口")
public class UserQuestionController extends BaseController {
    @Autowired
    private IUserQuestionService userQuestionService;

    //用户代码提交   请求方法  地址  参数  响应数据结构
    @PostMapping("/submit")
    @Operation(summary = "用户代码提交", description = "用户代码提交")
    @Parameter(name = HttpConstants.AUTHENTICATION, description = "jwt token", required = true,  in = ParameterIn.HEADER)
    @CheckUserStatus // 检查用户状态, 进行拉黑限制
    public R<UserQuestionResultVO> submit(@RequestBody UserSubmitDTO submitDTO) {
        log.info("用户代码提交,请求参数:{}", submitDTO);
        return userQuestionService.submit(submitDTO);
    }

    @PostMapping("/rabbit/submit")
    @Operation(summary = "RabbitMQ版用户代码提交", description = "RabbitMQ版用户代码提交")
    @Parameter(name = HttpConstants.AUTHENTICATION, description = "jwt token", required = true,  in = ParameterIn.HEADER)
    @CheckUserStatus // 检查用户状态, 进行拉黑限制
    public R<Void> rabbitSubmit(@RequestBody UserSubmitDTO submitDTO) {
        log.info("RabbitMQ版用户代码提交,请求参数:{}", submitDTO);
        return toR(userQuestionService.rabbitSubmit(submitDTO));
    }


    @GetMapping("/exe/result")
    @Operation(summary = "获取用户最近一次提交代码运行结果", description = "获取用户最近一次提交代码运行结果")
    @Parameter(name = HttpConstants.AUTHENTICATION, description = "jwt token", required = true,  in = ParameterIn.HEADER)
    @Parameter(name = "examId", description = "考试ID", required = false,  in = ParameterIn.QUERY)
    @Parameter(name = "questionId", description = "题目ID", required = true,  in = ParameterIn.QUERY)
    @Parameter(name = "currentTime", description = "当前时间", required = true,  in = ParameterIn.QUERY)
    @CheckUserStatus // 检查用户状态, 进行拉黑限制
    public  R<UserQuestionResultVO> exeResult(Long examId, Long questionId, String currentTime) {
        log.info("获取用户最近一次提交代码运行结果,请求参数:examId={},questionId={},currentTime={}", examId, questionId, currentTime);
        return R.ok(userQuestionService.exeResult(examId, questionId, currentTime));
    }
}
